package com.maxd.modules.coupon.mapper;

import com.maxd.modules.coupon.entity.CouponOrderDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Auther: Laban:yubo_010@163.com
 * @Date: 2020/11/14 18:32
 * @Description:
 */
@Repository
public interface CouponOrderDetailMapper extends JpaRepository<CouponOrderDetail, Long>{

    /**
     * 根据id修改
     */
    @Transactional
    @Modifying
    @Query(nativeQuery = true,value = "update sqx_coupon_order_detail set user_id=:#{#couponOrderDetail.userId}," +
            "order_id=:#{#couponOrderDetail.orderId},product_id=:#{#couponOrderDetail.productId}," +
            "coupon_amount=:#{#couponOrderDetail.couponAmount} where id=:#{#couponOrderDetail.id}")
    void updateCouponOrderDetailById(@Param("couponOrderDetail")CouponOrderDetail couponOrderDetail);


    /**
     * 根据订单id查询
     */
    @Query(nativeQuery = true,value = "select * from sqx_coupon_order_detail where order_id=:orderId")
    CouponOrderDetail findCouponOrderDetailByOrderId(@Param("orderId") String orderId);

}
